package com.atguigu.gulimall.product.service.impl;

import com.atguigu.gulimall.product.entity.SpuImagesEntity;
import com.atguigu.gulimall.product.service.SpuImagesService;
import com.atguigu.gulimall.product.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service("testService")
public class TestServiceImpl implements TestService {


    //代表当前方法的结果需要缓存，如果缓存汇总有，方法不用调用，如果缓存中没有才调用方法，最后将结果放入缓存
    //value:指定缓存的数据要放到哪个分区。【分区名称建议按照业务类型】
    //key:指定缓存key的名称
    @Cacheable(value = "test",key = "'test-key'")
    @Override
    public List list() {
        System.out.println("调用了");
        return Arrays.asList(1,2,3);
    }


//    // 删除指定分区内所有缓存 value = "test",allEntries = true
//    @CacheEvict(value = "test",allEntries = true)

//    //同时删除多个缓存
//    @Caching(evict = {
//            @CacheEvict(value = "test",key = "'cache-1'"),
//            @CacheEvict(value = "test",key = "'cache-2'")
//    })

    //删除模式，数据修改后删除缓存
    @CacheEvict
    @Override

//    @CachePut//双写模式 更新后将数据缓存到redis
    public void edit() {
        System.out.println("修改了");
    }

}
